home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2562 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: cpp question
  5. Date: 22 Jan 1996 07:59:28 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4e0580$9v5@solutions.solon.com>
  8. References: <4drm99$j0m@peabody.colorado.edu> <4dtf1f$21r4@news.gate.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4dtf1f$21r4@news.gate.net>, William Hutto <bhutto@gate.net> wrote:
  12. >In article <4drm99$j0m@peabody.colorado.edu>,
  13. >   woodjr@rintintin.Colorado.EDU (WOOD  JAMEY RYAN) spake:
  14. >;I have something like this:
  15. >;     #define USERLEN 8
  16. >;     #define HOSTLEN 15
  17.  
  18. >;     char name[] = "woodjr";
  19. >;     char host[] = "really.long.hostname.com";
  20. >;     char s[100];
  21.  
  22. >;     sprintf(s, "%.USERLENs@%.HOSTLENs", name, host);
  23.  
  24. >;And I want cpp to parse the sprintf line to:
  25.  
  26. >;     sprintf(s, "%.8s@%.15s", name, host);
  27.  
  28. >;Which it (of course) isn't doing.  Is there some syntax I
  29. >;can use to get it to do this?
  30.  
  31. >There shur is:
  32.  
  33. >     sprintf(s, "%.*s@%.*s", USERLEN, name, HOSTLEN, host);
  34.  
  35. >The asterisk in the width.precision fields in the formatting sequence allows 
  36. >you to include the size as an integer value in your parameter list.
  37.  
  38. Yes, but that doesn't do what he wants.  How about
  39. #define STR(x) RSTR(x)
  40. #define RSTR(x) #x
  41.  
  42.     sprintf(s, "%." STR(USERLEN) "s@%." STR(HOSTLEN) "s", name , host);
  43.  
  44. -s
  45. -- 
  46. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  47. C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
  48. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  49. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  50.